﻿using System.Data.Entity;
using System.Linq;
using Seed.Model;

namespace Seed.Data
{
    public class EntityContext : DbContext, IRepository
    {
        public EntityContext()
            : base("name=DefaultConnection")
        {
            //---
        }

        public DbSet<Person> People { get; set; }


        #region IRepository Implementation

        public IQueryable<T> Query<T>() where T : class
        {
            return Set<T>();
        }

        public T Find<T>(params object[] keyValues) where T : class
        {
            return Set<T>().Find(keyValues);
        }

        public void Add<T>(T entity) where T : class
        {
            Set<T>().Add(entity);
        }

        public void Update<T>(T entity) where T : class
        {
            Entry(entity).State = EntityState.Modified;
        }

        public void Remove<T>(T entity) where T : class
        {
            Set<T>().Remove(entity);
        } 

        #endregion
    }
}